#!/bin/bash

# 测试 Dify Chat API
# 用于诊断 400 Bad Request 错误

DIFY_URL="http://localhost/v1"
API_KEY="app-MnchjxJxe3YzEOn5GGkoM0QW"

echo "=== 测试 Dify Chat API ==="
echo "URL: ${DIFY_URL}/chat-messages"
echo ""

# 测试1: 最小请求
echo "测试1: 最小请求（只包含必需字段）"
curl -X POST "${DIFY_URL}/chat-messages" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {},
    "query": "测试问题",
    "response_mode": "blocking",
    "user": "test-user"
  }' \
  -v

echo -e "\n\n"

# 测试2: 不包含 inputs
echo "测试2: 不包含 inputs 字段"
curl -X POST "${DIFY_URL}/chat-messages" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "测试问题",
    "response_mode": "blocking",
    "user": "test-user"
  }' \
  -v

echo -e "\n\n"

# 测试3: 检查 API 信息
echo "测试3: 获取应用参数（如果支持）"
curl -X GET "${DIFY_URL}/parameters" \
  -H "Authorization: Bearer ${API_KEY}" \
  -v

echo -e "\n\n完成"
